import request from '@/utils/request'
export const getTaskById = id => request.get(`/tasks/${id}`)

export const getTasksByName = name => request.get(`/tasks/name?name=${name}`)

export const createTask = taskData => {
  const updateParams = {
    ...taskData,
    updatedAt: new Date().toISOString()
  }
  return request.post('/tasks', updateParams)
}

export const deleteTaskById = id => request.delete(`/tasks/${id}`)

export const updateTaskById = (id, taskData) => {
  const updateParams = {
    ...taskData,
    updatedAt: new Date().toISOString()
  }
  return request.put(`/tasks/${id}`, updateParams)
}

export const getAllTasks = () => request.get('/tasks')

export const getTeacherTasks = id => request.get(`/tasks/teacher/${id}`)

export const getStudentTasks = id => request.get(`/tasks/student/${id}`)
